<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="dataForm.fenceName"
          placeholder="电子围栏名称"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>

        <el-button type="danger" @click="synchronous()">同步</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="fenceName"
        header-align="center"
        align="center"
        label="名称"
      >
      </el-table-column>
      
      <el-table-column
        prop="lon"
        header-align="center"
        align="center"
        label="经度"
      >
      </el-table-column>
      <el-table-column
        prop="lat"
        header-align="center"
        align="center"
        label="纬度"
      >
      </el-table-column>
      <el-table-column
        prop="radius"
        header-align="center"
        align="center"
        label="半径(m)"
      >
      </el-table-column>
      
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间"
      >
      </el-table-column>
      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        label="描述"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageParams.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageParams.limit"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
    ></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./site-add-or-update";
export default {
  data() {
    return {
      options: [],
      dataForm: {
        fenceName: ""
      },
      dataList: [],
      pageParams: {
        page: 1,
        limit: 10
      },
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
    };
  },
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      let params = { ...this.pageParams, ...this.dataForm };
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/sys/gps/fence/page"),
        method: "get",
        params: this.$http.adornParams(params)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageParams.limit = val;
      this.pageParams.page = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageParams.page = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
   
    // 同步
    synchronous() {
      this.$confirm(
        `确定要进行同步操作吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/sys/gps/fence/save"),
          method: "get"
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "同步成功",
              type: "success",
              duration: 1500
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    }
  }
};
</script>
